<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选项库使用说明</title>

<style type='text/css' media='all'>@import url('userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='userguide.css' />

<script type="text/javascript" src="nav/nav.js"></script>
<script type="text/javascript" src="nav/prototype.lite.js"></script>
<script type="text/javascript" src="nav/moo.fx.js"></script>
<script type="text/javascript" src="nav/user_guide_menu.js"></script>

<meta http-equiv='expires' content='-1' />
<meta http-equiv= 'pragma' content='no-cache' />
<meta name='robots' content='all' />
<meta name='author' content='ExpressionEngine Dev Team' />
<meta name='description' content='CodeIgniter User Guide' />

</head>
<body>

<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('null');</script></div></div>
<div style="clear:both;height:43px;">
</div>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>CodeIgniter选项库使用说明</h1></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->


<!-- START CONTENT -->
<div id="content">

<h1>安装</h1>

<ul>
	<li>复制code目录下文件夹到CI application目录下。小心别盖掉已有的同名文件。</li>
	<li>利用code目录下b_sys_option.sql创建表，表名在models/option_model.php文件中写死，如果需要改表名的话，去这个文件里修改。</li>
	<li>修改autoload.php,config.php和database.php配置文件。
		<ul>
			<li>autoload.php:
				<textarea class="textarea" style="width:100%" cols="50" rows="2">
$autoload['libraries'] = array('database','dbcache');
$autoload['helper'] = array('bcore','url','language');</textarea>
			</li>
			<li>config.php保证base_url和index_page设置正确。
			</li>
			<li>database.php，注意dbprefix参数:
			<textarea class="textarea" style="width:100%" cols="50" rows="6">
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'ci';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = 'b_';</textarea>
			</li>
		</ul>
	</li>
	<li>注意必须使用UTF-8编码。</li>
</ul>


<h1>使用</h1>

<h2>查看效果</h2>
<p>
访问如下地址：http://localhost/ci/index.php/option，其中http://localhost/ci/为base_url，需要替换成config.php中base_url对应的配置。效果如下：
</p>
<img src="images/1.gif" alt="选项配置库">
<p>文本框不输入内容，直接提交，表单验证出错：</p>
<img src="images/2.gif" alt="选项配置库，表单验证出错">
<p>添加输入后提交，页面刷新，并且将值保存。</p>
<img src="images/3.gif" alt="选项配置库，添加数据">
<h2>增加选项</h2>

<p>很显然，在实际情况下，我们需要配置很多选项，而不只是一个网站名称这样简单。下面的代码演示如何轻松的添加多个配置选项。</p>
<textarea class="textarea" style="width:100%" cols="50" rows="36">
function index()
	{

	    $params = array(
	    	'sitename'=>array(
                'lang'=>lang('sitename'),
                'type'=>'text',
                'validation'=>'trim|required',
            ),
			'isopen'=>array(
                'lang'=>lang('isopen'),
                'type'=>'select',
                'validation'=>'required',
				'options'=>array('1'=>lang('open'),'2'=>lang('close'))
            ),
			'gender'=>array(
                'lang'=>lang('gender'),
                'type'=>'radio',
                'validation'=>'required',
				'options'=>array('1'=>lang('male'),'2'=>lang('female'))
            ),
			'hobby'=>array(
                'lang'=>lang('hobby'),
                'type'=>'checkbox',
                'validation'=>'required',
				'options'=>array('1'=>lang('male'),'2'=>lang('female'))
            ),
			'description'=>array(
                'lang'=>lang('description'),
                'type'=>'textarea',
                'validation'=>'required'
            ),
	    );
	    $this->load->library('option'); 
	    $this->option->editOptions($params);
	}</textarea>
<p>只需要将上面的代码复制到控制器option中，并替换index方法</p>
<p>同时添加语言：</p>
<textarea class="textarea" style="width:100%" cols="50" rows="11">
$lang['sitename'] = '网站名称';
$lang['isopen'] = '是否开放';
$lang['open'] = '开放';
$lang['close'] = '关闭';
$lang['submit'] = '提交';

$lang['gender'] = '性别';
$lang['hobby'] = '爱好';
$lang['description'] = '说明';
$lang['male'] = '男';
$lang['female'] = '女';</textarea>
<p>即可看到如下效果：</p>
<img src="images/4.gif" alt="增加选项配置">
<p>选项库支持类型为文本框、下拉列表、复选、单选、文本域共五种类型的设置。</p>

<h2>取选项的值</h2>
<p>在任何需要取选项值的地方，使用下面代码取值。</p>
<textarea class="textarea" style="width:100%" cols="50" rows="1"><?php echo op('sitename');?></textarea>
<p>我们在前面，输入sitename为“熊窝窝”，这里也将得到结果为“熊窝窝”。</p>
</div>
<!-- END CONTENT -->


<div id="footer">
<p><a href="#top">Top of Page</a></p>
<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 - 2011 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">EllisLab, Inc.</a></p>
</div>



</body>
</html>